{extend name="common:frm_base" /}
{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">管理排班</div>
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="{:url('bus_skd/handle')}" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">排班车辆</label>
                    <div class="layui-input-inline">
                        <select name="business_id" lay-filter="business">
                            <option value="" >请选择商家</option>
                            {foreach $business as $key=>$val}
                            <option value="{$val->id}" {if $val->id == $info->business_id}selected{/if} >{$val->name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="bus_id" id="bus_list">
                            <option value="" >请选择车辆</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">排班时间</label>
                        <div class="layui-input-inline" style="width: 200px;">
                            <input type="text" name="skd_date" autocomplete="off" value="{$info->skd_date}" class="layui-input skd_date">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">开始城市</label>
                        <div class="layui-input-inline" >
                            <select name="begin_city" >
                                <option value="">请选择开始城市(不选择由系统匹配)</option>
                                {foreach $city_list as $key=>$val}
                                <option value="{$val->id}" {if $info->begin_city == $val->id}selected{/if} >{$val->name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">结束城市</label>
                        <div class="layui-input-inline" >
                            <select name="end_city" >
                                <option value="">请选择开始城市(不选择由系统匹配)</option>
                                {foreach $city_list as $key=>$val}
                                <option value="{$val->id}" {if $info->end_city == $val->id}selected{/if} >{$val->name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">金额</label>
                        <div class="layui-input-inline">
                            <input type="text" name="price" autocomplete="off" value="{$info->price}" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="status" checked value="{$info->getData('status')}" title="{$info->status}">
                    </div>
                </div>
                {:token()}
                <input type="hidden" value="{$act}" name="act" />
                <input type="hidden" value="{$info['id']|default=''}" name="id" />
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-user-front-submit" id="LAY-user-front-submit" value="确认">
                </div>
                <!--<div class="layui-form-item layui-layout-admin">-->
                <!--<div class="layui-input-block">-->
                <!--<div class="layui-footer" style="left: 0;">-->
                <!--<button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>-->
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                <!--</div>-->
                <!--</div>-->
                <!--</div>-->
            </form>
        </div>
    </div>
</div>


<script>
    layui.config({
        base: '__LAYUIADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form
            ,laydate = layui.laydate;

        form.render(null, 'component-form-group');
        var reload_select = function(){
            form.render('select');
        }

        var business_id = "{$info->business_id}";
        var bus_id = "{$info->bus_id}";
        if (typeof(business_id) != "undefined"){
            show_bus(business_id, bus_id);
        }

        laydate.render({
            elem: '.skd_date'
            ,type: 'date'
        });

        form.on('select(business)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象.
            var business_id = data.value;
            show_bus(business_id);
        });

        function show_bus(business_id, bus_id){
            if (typeof (bus_id) == 'undefined'){
                bus_id = 0;
            }
            $.ajax({
                type: "POST",
                url: "{:url('bus/getBus')}",
                data: {business_id:business_id},
                dataType: "json",
                success: function(data){
                    if(data.code == 0){
                        var html = "<option value=''>请选择车辆</option>";
                        $.each(data.data,function(i,item){
                            var select_html = bus_id == item.id? "selected":"";
                            html += "<option value='"+item.id+"' "+select_html+" >"+item.bus_no+"</option>";
                        });
                        $("#bus_list").html(html);
                        reload_select();
                    }
                }
            });
        }

    });
</script>
{/block}